package cn.db101.api.complex.enumration


enum class ResultCodeEnum(var code: Int, var msg: String) {
    /** 结果返回成功  */
    SUCCESS(200, "成功"),
    CREATED(201, "用户新建或修改成功"),
    ACCEPTED(202, "接收成功"),
    NO_CONTENT(204, "无数据返回"),
    FLUSHTOKEN(210, "更新token"),
    INVALID_REQUEST(400, "请求错误"),
    UNLOGIN(401, "未登录的用户"),
    LOGIN_FAIL(402, "登录失败"),
    FORBIDDEN(403, "没有对应的权限"),
    VALID_MODIFY(450, "错误修改项"),
    USER_EXISTS(406, "用户已经存在"),
    USER_REGISTERED(407, "用户已经注册"),
    REQUEST_SIGN_ERROR(420, "请求参数错误"),
    TOKEN_VERIFY_ERROR(421, "TOKEN验证失败"),
    TOKEN_TIME_EXPIRE(422, "TOKEN有效期过期"),
    SIGN_EMPTY(430, "签名为空"),
    SIGN_ERROR(431, "签名失败"),
    CODE_USER_EXISTS(440, "码已经存在，请勿重复开通"),
    CODE_USER_DELETE(441, "码用户被禁用，拉码失败"),
    USER_RE_REGISTER(450, "用户已在其他设备登陆"),

    /** 系统错误,设置在全局异常 */
    SYSTEM_ERROR(500, "系统错误"),
    UPDATE_FAILED(501, "更新失败"),
    PARAM_DUPLICATE(701, "参数重复"),
    PARAM_ERROR(702, "参数错误"),
    IMAGE_INVALID(5011, "图片校验失败");


    companion object {
        fun getByCode(code: Int): ResultCodeEnum? {
            for (ec in values()) {
                if (ec.code === code) {
                    return ec
                }
            }
            return null
        }
    }
}
